<?php
///////////////////////////////////////////////////////
// Created by G.M.Sundar
// on 06/10/24
//////////////////////////////////////////////////////


include(DOCINCLUDES."global_files/global_pgsql.inc");



require_once DOCINCLUDES.'spreadsheet/Writer.php';


$db = new cDatabase();






// Creating a workbook
$workbook = new Spreadsheet_Excel_Writer();

// sending HTTP headers
$workbook->send('test_sundar1.xls');

// Creating a worksheet
$worksheet =& $workbook->addWorksheet('My first worksheet');

// The actual data


/*
$db->query = " SELECT transaction_date ,stock_category_id,stock_type_id,grade_id,mst120.quantity,location_id,remarks,sbsd120.size_id,sbsd120.quantity,sbsd120.batch_id from  material_stock_transaction_120 mst120 join stock_batch_size_details_120 sbsd120 on mst120.stock_transaction_id=sbsd120.transaction_id  where transaction_type_id='3' and transaction_type='i' and mst120.stock_transaction_id=1"*/;
$db->query = "SELECT * from _100350.master_report";
$db->runQuery();
$table_details = $db->returnArrays();


        if ($table_details)
                {
                	$colcount=0; //for setting the footer colspan
			foreach($table_details[0] as $key=>$value)
                                {
				$worksheet->write(0,$colcount ,$key );
				$colcount++;
				}
			}
                $i=0;
                $cnt=count($table_details);
		
                for($j=0; $j<$cnt; $j++)
                        {

			$cell=0;
			foreach($table_details[$j] as $key=>$value)
                                {

				$worksheet->write($j+1,$cell ,$value );
				$cell++;
                                }

			}
$workbook->close();
?>